package com.test.fundible.fundible_00_analytics.fundibletimezone

import android.text.TextUtils
import java.util.*

object FundibleTimeZoneUtil {

    /**
     * 获取当前需要回传数据的地区
     */
    private fun currentTimeZoneSupportCountrys_fundible(): List<String> {
        val list = mutableListOf<String>()
        val timeZoneId = TimeZone.getDefault().id.toString()
        println("======timeZoneId=$timeZoneId")
        when (timeZoneId) {
            FundibleTimeZoHostEnum.GHA.timeZoId -> {
                list.add(FundibleTimeZoHostEnum.GHA.country)
            }
            FundibleTimeZoHostEnum.FCFA.timeZoId -> {
                list.add(FundibleTimeZoHostEnum.FCFA.country)
            }
            FundibleTimeZoHostEnum.KSH.timeZoId -> {
                list.add(FundibleTimeZoHostEnum.KSH.country)
            }
            FundibleTimeZoHostEnum.UGX.timeZoId -> {
                list.add(FundibleTimeZoHostEnum.UGX.country)
            }
            FundibleTimeZoHostEnum.NAIRA.timeZoId -> {
                list.add(FundibleTimeZoHostEnum.NAIRA.country)
            }
            FundibleTimeZoHostEnum.VIETNAM.timeZoId -> {
                list.add(FundibleTimeZoHostEnum.VIETNAM.country)
            }
        }
        return list
    }

    /**
     *  转换为真正需要上报数据的服务器地址列表
     *
     * @param list 配置的服务器地址
     */
    fun covertToRealTargetServers_fundible(list: List<String>): List<String> {
        val curTimeZoneSupportCountrys: List<String> = currentTimeZoneSupportCountrys_fundible()
        val serviceTargetUrlList = list.filter { url ->
            curTimeZoneSupportCountrys.any { country -> url.endsWith(country) }
        }
        val resultTargetUrlList = serviceTargetUrlList.ifEmpty { list }
        return resultTargetUrlList
    }

    fun getTimeZoneID_fundible():String{
        val result = TimeZone.getDefault().id
        if (TextUtils.isEmpty(result)) return ""
        return result
    }
}